home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wstype / source / disp.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  10KB  |  404 lines

  1. /***   [disp.c]
  2. *
  3. *    表示方法変更インターフェイスウィンドウ 関連        (C)ささがわ
  4. *
  5. *    For GNU C Compiler (GCC)   Version 1.39
  6. *
  7. ***/
  8.  
  9. #include <stdio.h>
  10. #include <kyb.h>
  11. #include <mos.h>
  12. #include "graph.h"
  13. #include "window.h"
  14. #include "icn.h"
  15. #include "txwind.h"
  16. #include "disp.h"
  17. #include "others.h"
  18. #include "optparse.h"
  19.  
  20. #define WH_CAN        0
  21. #define WH_TITLE    1
  22. #define WH_ON        2
  23. #define WH_OTHER    -1
  24.  
  25. extern int    PAL_Back;
  26. extern int    PAL_Black;
  27. static int    wx, wy, pars_lgcol;
  28. static char    pars[5];
  29. static struct txinfo_t    txi = {
  30.     { 0, 0, NULL, NULL}, "", 0, 0, 0, 0, 16, 1, 0, 8, 80, 0, 4
  31. };
  32. static const short    table[21][5] = {
  33.     { 30, 101, 49, 64, 10},        { 30, 101, 69, 84, 11},
  34.     { 30, 101, 110, 125, 20},    { 30, 101, 130, 145, 21},
  35.     { 30, 93, 171, 186, 30},    { 30, 93, 191, 206, 31},
  36.     { 102, 165, 171, 186, 32},    { 102, 165, 191, 206, 33},
  37.     { 199, 262, 49, 64, 40},    { 199, 262, 69, 84, 41},
  38.     { 199, 262, 89, 104, 42},    { 271, 334, 49, 64, 43},
  39.     { 271, 334, 69, 84, 44},    { 199, 334, 130, 145, 50},
  40.     { 199, 223, 153, 168, 51},    { 224, 243, 151, 170, 52},
  41.     { 245, 272, 151, 170, 53},    { 274, 293, 151, 170, 54},
  42.     { 6, 25, 6, 25, WH_CAN},    { 27, 342, 6, 25, WH_TITLE},
  43.     { 252, 331, 181, 202, WH_ON}
  44. };
  45.  
  46. static void    Draw_window(void);
  47. static int    Where(int, int);
  48. static void    inkey(void);
  49. static void    disp_keta(int);
  50. static void    OnOff(int, int);
  51. static void    disp_onoff(void);
  52. static void    SUB_on(int);
  53. static void    InDe_lgcol(int);
  54. static int    InDe_lgcol_sub(int);
  55. static void    SUB_setlinegap(int, struct txinfo_t *);
  56.  
  57. void DSP_init(void) {
  58.     int        i;
  59.     short    p[5];
  60.     
  61.     for (i = 0; i < 5; p[i++] = -1);
  62.     OPT_disp(p);
  63.     
  64.     if (p[0] >= 0)    txi.tabd = p[0];
  65.     if (p[1] >= 0)    txi.crd = p[1];
  66.     if (p[2] >= 0) {
  67.         switch (p[2]) {
  68.             case 1:
  69.             case 2:
  70.             case 4:        txi.tab = p[2];    break;
  71.               default:    txi.tab = 8;    break;
  72.         }
  73.     }
  74.     if (p[3] >= 0 && 4 >= p[3])    SUB_setlinegap(p[3], &txi);
  75.     if (p[4] == 0)
  76.         txi.lgcolw = 1;
  77.     else if (20 <= p[4] && p[4] <= 500)
  78.         txi.lgcol = p[4];
  79. }
  80.  
  81. static void SUB_setlinegap(int n, struct txinfo_t *inf) {
  82.     switch (n) {
  83.         case 0:        inf->linegap = 0;    break;
  84.         case 1:        inf->linegap = inf->fontx / 8;    break;
  85.         case 3:        inf->linegap = inf->fontx / 2;    break;
  86.         case 4:        inf->linegap = inf->fontx * 3 / 4;    break;
  87.         default:    inf->linegap = inf->fontx / 4;    break;
  88.     }
  89. }
  90.  
  91. void DSP_change(void) {
  92.     WIND_disp(1, &txi, 0, 0);
  93. }
  94.  
  95. void DSP_set(struct txinfo_t *Info) {
  96.     *Info = txi;
  97. }
  98.  
  99. int WIND_disp(int mode, struct txinfo_t *Info, int x, int y) {
  100.     int        ret = 0;
  101.     struct RECT    a, b;
  102.     struct txinfo_t    pInfo;
  103.     
  104.     pars[0] = Info->crd ? 0 : 1;
  105.     pars[1] = Info->tabd ? 0 : 1;
  106.     switch (Info->tab) {
  107.         case 1:        pars[2] = 0;    break;
  108.         case 2:        pars[2] = 1;    break;
  109.         case 4:        pars[2] = 2;    break;
  110.         default:    pars[2] = 3;    break;
  111.     }
  112.     if (Info->linegap == 0)    pars[3] = 0;
  113.     else if (Info->linegap == Info->fontx / 8)    pars[3] = 1;
  114.     else if (Info->linegap == Info->fontx / 4)    pars[3] = 2;
  115.     else if (Info->linegap == Info->fontx / 2)    pars[3] = 3;
  116.     else    pars[3] = 4;
  117.     pars[4] = Info->lgcolw ? 0 : 1;
  118.     pars_lgcol = Info->lgcol;
  119.     
  120.     if (mode) {
  121.         wx = 146;
  122.         wy = 133;
  123.         a.x1 = 319;    a.y1 = 259;
  124.         a.x2 = 320;    a.y2 = 260;
  125.         b.x1 = wx;    b.y1 = wy;
  126.         b.x2 = wx + 348;    b.y2 = wy + 214;
  127.         afterImage(&a, &b);
  128.     } else {
  129.         wx = x;
  130.         wy = y;
  131.     }
  132.     
  133.     Draw_window();
  134.     while (!ret) {
  135.         char    mb;
  136.         int        mx, my, wh;
  137.         
  138.         CLOCK(0);
  139.         if (MOS_rdpos(&mb, &mx, &my), !(mb & 1))
  140.             continue;
  141.         
  142.         if ((wh = Where(mx, my)) == WH_CAN) {
  143.             if (Button(wx + 6, wy + 6, wx + 25, wy + 25))
  144.                 ret = -1;
  145.         } else if (wh == WH_TITLE) {
  146.             struct RECT    s, w;
  147.             
  148.             w.x1 = wx;    w.y1 = wy;
  149.             w.x2 = wx + 348;    w.y2 = wy + 214;
  150.             s.x1 = 0;    s.y1 = 40;    s.x2 = 639;    s.y2 = 463;
  151.             if (dragWindow(mx, my, &w, &s, 0, 0)) {
  152.                 wx = w.x1;    wy = w.y1;
  153.                 MOS_disp(0);
  154.                 EGB_cls(0);
  155.                 MOS_disp(1);
  156.                 Draw_window();
  157.             }
  158.         } else if (wh == WH_ON) {
  159.             if (Button(wx + 252, wy + 181, wx + 331, wy + 202))
  160.                 ret = 1;
  161.         } else if (wh == WH_OTHER) {
  162.             while (MOS_rdpos(&mb, &mx, &my), mb & 1);
  163.         } else if (wh / 10 == 5) {
  164.             SUB_on(wh > 50 ? 51 : 50);
  165.             
  166.             if (wh == 52 || wh == 54)
  167.                 InDe_lgcol(wh == 52 ? 0 : 1);
  168.             else if (wh == 53) {
  169.                 if (Button(wx + 245, wy + 151, wx + 272, wy + 170))
  170.                     inkey();
  171.             } else
  172.                 while (MOS_rdpos(&mb, &mx, &my), mb & 1);
  173.         } else {
  174.             SUB_on(wh);
  175.             while (MOS_rdpos(&mb, &mx, &my), mb & 1);
  176.         }
  177.     }
  178.     if (ret == -1)    return 0;
  179.     
  180.     pInfo = *Info;
  181.     Info->crd = pars[0] ? 0 : 1;
  182.     Info->tabd = pars[1] ? 0 : 1;
  183.     switch (pars[2]) {
  184.         case 0:        Info->tab = 1;    break;
  185.         case 1:        Info->tab = 2;    break;
  186.         case 2:        Info->tab = 4;    break;
  187.         default:    Info->tab = 8;    break;
  188.     }
  189.     SUB_setlinegap(pars[3], Info);
  190.     if (Info->lgcolw = pars[4] ? 0 : 1)    Info->col = 0;
  191.     Info->lgcol = pars_lgcol;
  192.     
  193.     ret = 0;
  194.     if (pInfo.crd != Info->crd)        ret += 1;
  195.     if (pInfo.tabd != Info->tabd)    ret += 2;
  196.     if (pInfo.tab != Info->tab)        ret += 4;
  197.     if (pInfo.linegap != Info->linegap)    ret += 8;
  198.     if (!(pInfo.lgcolw && Info->lgcolw || !pInfo.lgcolw && !Info->lgcolw && pInfo.lgcol == Info->lgcol))
  199.         ret += 16;
  200.     
  201.     return ret;
  202. }
  203.  
  204. static void Draw_window(void) {
  205.     int        i;
  206.     struct opnwin_t    opw;
  207.     static const char    *str[] = {
  208.         "◆ 改行記号の表示", "○ する", "○ しない",
  209.         "◆ タブ記号の表示", "○ する", "○ しない",
  210.         "◆ タブ長", "○ 1    ○ 4", "○ 2    ○ 8",
  211.         "◆ 行間隔", "○ 0     ○ 1/2", "○ 1/8   ○ 3/4", "○ 1/4",
  212.         "◆ 横幅", "○ ウィンドウ幅と同じ", "○"
  213.     };
  214.     static const short    cord[][2] = {
  215.         { 14, 44}, { 30, 64}, { 30, 84},
  216.         { 14, 105}, { 30, 125}, { 30, 145},
  217.         { 14, 166}, { 30, 186}, { 30, 206},
  218.         { 183, 44}, { 199, 64}, { 199, 84}, { 199, 104},
  219.         { 183, 125}, { 199, 145}, { 199, 168}
  220.     };
  221.     
  222.     opw.title = "表示方法の変更";
  223.     opw.x1 = wx;
  224.     opw.y1 = wy;
  225.     opw.x2 = opw.x1 + 348;
  226.     opw.y2 = opw.y1 + 214;
  227.     opw.shdw = 1;
  228.     opw.canb = 1;
  229.     opw.nopt = 0;
  230.     opw.wopt = NULL;
  231.     opw.expb = 0;
  232.     opw.ord = 0;
  233.     MOS_disp(0);
  234.     drawWindow(&opw);
  235.     
  236.     EGB_line(wx + 174, wy + 26, wx + 174, wy + 209, PAL_Black);
  237.     EGB_line(wx + 5, wy + 87, wx + 174, wy + 87, PAL_Black);
  238.     EGB_line(wx + 5, wy + 148, wx + 174, wy + 148, PAL_Black);
  239.     EGB_line(wx + 174, wy + 107, wx + 343, wy + 107, PAL_Black);
  240.     EGB_line(wx + 174, wy + 174, wx + 343, wy + 174, PAL_Black);
  241.     
  242.     for (i = 0; i < 16; i++)
  243.         EGB_str2(str[i], wx + cord[i][0], wy + cord[i][1], PAL_Black);
  244.     
  245.     DrawButton(1, wx + 223, wy + 150, wx + 244, wy + 171);
  246.     EGB_box(wx + 244, wy + 150, wx + 273, wy + 171, PAL_Black);
  247.     DrawButton(1, wx + 273, wy + 150, wx + 294, wy + 171);
  248.     EGB_str2("-", wx + 226, wy + 168, PAL_Black);
  249.     EGB_str2("+", wx + 276, wy + 168, PAL_Black);
  250.     
  251.     DrawButton(1, wx + 251, wy + 180, wx + 332, wy + 203);
  252.     for (i = 0; i < 2; i++)
  253.         EGB_str2(" 実    行 ", wx + 252 + i, wy + 199, PAL_Black);
  254.     MOS_disp(1);
  255.     disp_onoff();
  256.     disp_keta(0);
  257. }
  258.  
  259. static void InDe_lgcol(int id) {
  260.     int        flpush = 1, fllast, lx, ly;
  261.     int        mx, my;
  262.     char    mb;
  263.     
  264.     lx = wx + (id ? 274 : 224);
  265.     ly = wy + 151;
  266.     
  267.     EGB_rev(1, lx, ly, lx + 19, ly + 19);
  268.     fllast = InDe_lgcol_sub(id);
  269.     TIMER_set(20);
  270.     
  271.     while (MOS_rdpos(&mb, &mx, &my), mb & 1) {
  272.         int        whres;
  273.         
  274.         whres = Where(mx, my) == (id ? 54 : 52);
  275.         if (!whres && flpush || whres && !flpush) {
  276.             EGB_rev(1, lx, ly, lx + 19, ly + 19);
  277.             flpush = !flpush;
  278.         }
  279.         
  280.         if (flpush && TIMER() && !fllast)
  281.             fllast = InDe_lgcol_sub(id);
  282.     }
  283.     
  284.     if (flpush)
  285.         EGB_rev(1, lx, ly, lx + 19, ly + 19);
  286. }
  287.  
  288. static int InDe_lgcol_sub(int id) {
  289.     int        result = 1;
  290.     
  291.     if (id && pars_lgcol < 500 || !id && pars_lgcol > 20) {
  292.         id ? pars_lgcol++ : pars_lgcol--;
  293.         disp_keta(0);
  294.         result = 0;
  295.     }
  296.     
  297.     return result;
  298. }
  299.  
  300. static int Where(int x, int y) {
  301.     int        i, ret = WH_OTHER;
  302.     
  303.     x -= wx;
  304.     y -= wy;
  305.     for (i = 0; i < 21; i++) {
  306.         const short    *p;
  307.         
  308.         p = table[i];
  309.         if (p[0] <= x && x <= p[1] && p[2] <= y && y <= p[3]) {
  310.             ret = p[4];
  311.             break;
  312.         }
  313.     }
  314.     
  315.     return ret;
  316. }
  317.  
  318. static void inkey(void) {
  319.     int        ret = 0;
  320.     unsigned    kadr, kcode;
  321.     
  322.     pars_lgcol = 0;
  323.     disp_keta(1);
  324.     do {
  325.         int        mx, my;
  326.         char    mb;
  327.         
  328.         kcode = KYB_read(1, &kadr);
  329.         MOS_rdpos(&mb, &mx, &my);
  330.         if (kcode == '\r' || (mb & 1 && Where(mx, my) != 53)) {
  331.             ret = 1;
  332.             break;
  333.         } else if (kcode == 0x1b) {
  334.             pars_lgcol = 0;
  335.             disp_keta(1);
  336.             continue;
  337.         } else if (kcode < '0' || '9' < kcode || pars_lgcol > 99)
  338.             continue;
  339.         
  340.         pars_lgcol *= 10;
  341.         pars_lgcol += kcode - '0';
  342.         disp_keta(1);
  343.     } while (!ret);
  344.     EGB_rev(1, wx + 245, wy + 151, wx + 272, wy + 170);
  345.     
  346.     if (pars_lgcol < 20) {
  347.         pars_lgcol = 20;
  348.         disp_keta(0);
  349.     } else if (pars_lgcol > 500) {
  350.         pars_lgcol = 500;
  351.         disp_keta(0);
  352.     }
  353. }
  354.  
  355. static void disp_keta(int mode) {
  356.     int        c1, c2;
  357.     char    n[10];
  358.     
  359.     sprintf(n, "%3d", pars_lgcol);
  360.     c1 = mode ? 15 : PAL_Black;
  361.     c2 = mode ? 8 : PAL_Back;
  362.     MOS_disp(0);
  363.     EGB_str3(n, wx + 247, wy + 168, c1, c2);
  364.     MOS_disp(1);
  365. }
  366.  
  367. static void OnOff(int wh, int sw) {
  368.     int        i, x = 0, y = 0;
  369.     
  370.     for (i = 0; i < 21; i++) {
  371.         if (table[i][4] == wh) {
  372.             x = table[i][0];
  373.             y = table[i][3];
  374.             break;
  375.         }
  376.     }
  377.     
  378.     EGB_str3(sw ? "●" : "○", wx + x, wy + y, PAL_Black, PAL_Back);
  379. }
  380.  
  381. static void disp_onoff(void) {
  382.     int        i;
  383.     
  384.     MOS_disp(0);
  385.     for (i = 0; i <= 4; i++)
  386.         OnOff((i + 1) * 10 + pars[i], 1);
  387.     MOS_disp(1);
  388. }
  389.  
  390. static void SUB_on(int wh) {
  391.     int        a;
  392.     
  393.     a = wh / 10;
  394.     a = a * 10 + pars[a - 1];
  395.     if (wh == a)
  396.         return;
  397.     
  398.     MOS_disp(0);
  399.     OnOff(a, 0);
  400.     OnOff(wh, 1);
  401.     pars[wh / 10 - 1] = wh % 10;
  402.     MOS_disp(1);
  403. }
  404.